<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019-10-11
 * Time: 19:41
 */

namespace iBrand\Shop\Core\Listeners;


use iBrand\Component\Point\Model\Point;
use iBrand\Shop\Core\Models\User;

class UserEventListener
{
    public function onCreateUser($user_id)
    {
        if (!Point::where('action', 'register_gift')->where('user_id', $user_id)->first()) {
            Point::create([
                'user_id' => $user_id,
                'action' => 'register_gift',
                'note' => '优享会员新人礼',
                'value' => 2000,
                'status' => 0]);
        }
    }

    public function subscribe($events)
    {
        $events->listen(
            'user.created.gift',
            'iBrand\Shop\Core\Listeners\UserEventListener@onCreateUser'
        );

    }
}